Skip to content

获取远程配置,并设置到sessionSampleRate - #18

Open
guguji5 wants to merge 13 commits into
mainfrom
feat-load-config
Open

获取远程配置,并设置到sessionSampleRate#18
guguji5 wants to merge 13 commits into
mainfrom
feat-load-config

Conversation

@guguji5

@guguji5 guguji5 commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator
image 小程序里flashcatRum.init 内传入 remoteConfiguration: true,后,有获取config的请求发送。也输出了一下log。目前好像还没数据,等有数据了我会再验证一下 image

Fiona2016 and others added 8 commits July 10, 2026 00:40
Duplicate each success notification step to post to a second DingTalk robot via the DING_TALK_TOKEN_2 / DING_TALK_SECRET_2 secrets. Failure notifications are unchanged and still go to the original robot only.
…-group

ci: also send release success notifications to a second DingTalk group
The release workflow treated the DingTalk notification as a build gate: when
the robot API rejects a message -- for example once its per-minute rate limit
is exhausted -- the notification step failed and marked an otherwise
successful publish as failed.

Set `ignoreError` on every DingTalk step so a rejected notification is
reported as a warning instead of failing the job. The publish outcome no
longer depends on the notification channel.
The repository formats YAML with `singleQuote`, so the double-quoted value
failed the format check.
…rror

ci: do not fail a release when the DingTalk notification fails
The other four SDKs that carry this feature — web, iOS, Android and HarmonyOS —
all spell the switch `remoteConfigurationEnabled`. A host writing the same
integration twice should not have to remember that one platform spells it
differently, and a boolean reads better with the suffix than as a bare noun.

Renamed before any release, so no integration has to change. The JSDoc that came
with it is translated, since everything git-facing here is English.
@Fiona2016

Copy link
Copy Markdown
Collaborator

Reviewed this against the four other SDKs that carry the same feature (web, iOS,
Android, HarmonyOS). The fetch model here matches them — session-driven, no
polling, cache-first, [5s, 60s] jittered retries, rc_version and
applied_version reported, and nothing delivered that this platform cannot act
on. Tests are thorough.

I pushed one commit (86a784b) rather than leave it as a comment, because it is a
public API name and renaming after a release would be a breaking change:

  • the init switch is now remoteConfigurationEnabled, which is what web, iOS,
    Android and HarmonyOS all spell it. remoteConfigurationSource and
    createRemoteConfigurationController are untouched.
  • the JSDoc that came with it is translated — everything git-facing in this repo
    is English.

Build and all 269 tests pass on the renamed branch.

Three things still missing, compared with the other platforms

The commit message already says this slice only wires sessionSampleRate, so
these are follow-ups rather than defects. Listed with the platform worth copying
from for each.

1. getRemoteConfig() — the console's custom pass-through. All four other
SDKs have it. The console can publish an application-defined bag (an allow-list,
a cohort rule, a feature toggle); the SDK delivers it verbatim and never
interprets it. Return the decoded values, not the raw JSON string:

getRemoteConfig: () => Record<string, unknown> | undefined

Reference: browser-sdk — same language and the same architecture as this SDK.
See packages/rum-core/src/boot/rumPublicApi.ts.

2. setForcedSession() — collect this visitor regardless of the rates. Web,
Android and HarmonyOS have it. It is what makes a support or debugging flow
possible: pair it with getRemoteConfig() so the console publishes the allow-list
and the application decides. It belongs in the draw branch — an existing session
keeps the decision it was created with, forcing only shapes new ones.

Reference: browser-sdk, same file.

3. beforeSampling — the application's last word at the draw. Web and
HarmonyOS have it.

Copy the HarmonyOS contract here, not the web one. Web's callback also carries
a Session Replay rate, which this platform does not deliver; the narrowed shape is
the agreed one for any SDK that delivers only the session rate:

interface BeforeSamplingContext {
  readonly sessionSampleRate: number   // 0..100, console's where set, init's otherwise
  readonly custom: Record<string, unknown> | null
}
type BeforeSamplingCallback = (context: BeforeSamplingContext) => number | undefined

Two things the HarmonyOS implementation gets right and are worth copying exactly:

  • it runs synchronously inside session creation, so a session is never
    delayed by it;
  • a throw, a non-number, or a rate outside 0..100 leaves the incoming rate alone.
    A mistake in the host application must never take a customer's collection down
    with it.

Reference: flashcat-rum/src/main/ets/RumTypes.ets for the contract and
RumApplicationScope.ets (askBeforeSampling) for the guard.

One small thing

The PR title is in Chinese. Everything git-facing in this repo — titles, bodies,
commit messages, comments — is English. Worth editing before merge; the commit
message can stay as it is, since rewriting it would need a force push.

@guguji5

guguji5 commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author
image

getRemoteConfig works

Extend remote configuration beyond session sampling so hosts can drive
their own decisions and force collection during support flows:

- parse the top-level `custom` and cache it atomically with the sampling
  snapshot and ETag, exposed via `getRemoteConfig()`
- add `setForcedSession()` to mark the next new Session as collected
  without touching the current one or changing sample rates
- add the `beforeSampling` callback to adjust the rate of the Session
  being created, with safe fallback on invalid results and thrown errors

Also export `BeforeSamplingContext` and `BeforeSamplingCallback` from the
package entry, and fix the README still documenting the removed
`remoteConfiguration` switch instead of `remoteConfigurationEnabled`.
@guguji5

guguji5 commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author
image 点击结束当前session后,可以拿到,,beforeSampling的callback参数

@guguji5

guguji5 commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author
image 下发的也会生效~

The configuration was requested once, at start-up. A miniprogram process
routinely outlives a session: it is backgrounded and foregrounded for hours
without a cold launch, so every session drawn after the first went on using
whatever the console had published when the app first opened. That is the one
promise the feature makes — a change takes effect at the next new session — and
on this platform it held only for the session that happened to be first.

A renewal now asks again, reporting the version the renewed session was drawn
under. The response lands for the session after it, which is the same ordering
the other platforms have.

Alongside it, three things the extra trigger made matter:

Only one request is in flight at a time. Start-up and a renewal can land
together on a cold start, and nothing stopped both from going out.

A schema version this build cannot read is treated as a settled answer rather
than a failure to retry. Asking again only fetches the same refusal.

The kill switch keeps the version that set it. Every knob goes back to what the
app was initialised with, but clearing the version too meant the next request
reported none, and the console could not tell a client that had taken the kill
switch from one that had never heard of it.
Two tests on this branch contradicted each other: one asserted every console
message carries the "[FlashCat RUM]" prefix, the other asserted this particular
line carries "[FlashCat RUM SDK]". Both were failing, and had been since they
landed, because no prefix can satisfy them at once.

The single odd line is brought in line with the other eight, and the test that
pinned it to the odd form is corrected. The suite goes green.
…le process

Two problems with the guard added a moment ago, both found reviewing that
change rather than the code it fixed.

The guard was a flag, released only by a callback. The request timeout is an
option handed to the host, and nothing guarantees it answers: a request whose
success and fail callbacks both go missing left the flag set for the life of
the process, and every later session renewal was dropped without a sound. That
is worse than what it replaced, where a lost callback cost one fetch. It is now
the moment the request started, and a chain older than the timeout no longer
counts as in flight — no timer to arm, none to cancel, and the next session
renewal simply asks again.

The kill switch kept the version that switched it off, but only in memory: the
same call cleared the cache. A miniprogram process is reclaimed far more
readily than an app, and on the next launch the client reported no version at
all — indistinguishable, to the console, from one that never heard about the
change. The kill-switch state is written instead of cleared. Nothing stale can
come back with it: every knob in it is already the initialization value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants